package com.leaf.lowcode.service;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.springframework.http.*;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.client.RestTemplate;

@Component
public class QueryToken {
   // @Scheduled(initialDelay =  30*1000, fixedRate = 30*1000)
    public String execute(){
        RestTemplate restTemplate = new RestTemplate();
        HttpHeaders headers = new HttpHeaders();
       String url="https://work.spic.com.cn:8443/mgr/portal/token/getToken.do";

        // String url="https://workuat.spic.com.cn/mgr/portal/token/getToken.do";

        headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
        MultiValueMap<String, String> map= new LinkedMultiValueMap<String, String>();
        map.add("developerId", "qwec8e22bfd2ca458b8a67b0aba8072c0b");
        map.add("developerKey", "ODg2N2NjYzgtNTRmNC00OWUxLTg3N2EtZDYyY2E0MTliNGZj");

        /*map.add("developerId", "qw4a65023da7604ebaac9830432dd75c07");
        map.add("developerKey", "ODdkNTM5N2UtODgzNi00MjUyLTg3MmItYzhkYjcyN2RjMjIy");*/


        HttpEntity<MultiValueMap<String, String>> request = new HttpEntity<MultiValueMap<String, String>>(map, headers);
        System.out.println("进入");
        ResponseEntity<String> response = restTemplate.postForEntity(url, request, String.class);
        String body = response.getBody();
        JSONObject objects = JSON.parseObject(body);
        String token = (String) ((JSONObject) objects.get("data")).get("token");
        return token;

    }
}
